package ru.rchervot.sanasar.client.view;


import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.Widget;

public class RootViewDefault implements RootPresenter.Display {
	private Presenter presenter;
	private final FactoryHeaderView factoryHeader;
	
	private static final String HEADER_ID = "Header";
	private static final String MODULE_CANDIDATES_ID = "ModuleCandidates";
	private static final String MODULE_COMPANIES_ID = "ModuleCompanies";
	private static final String MODULE_ORDERS_ID = "ModuleOrders";
	private static final String MODULE_REPORTS_ID = "ModuleReports";
	private static final String MODULE_SETTINGS_ID = "ModuleSettings";
	
	public RootViewDefault(FactoryHeaderView factoryHeader) {
		this.factoryHeader = factoryHeader;
		
		RootPanel.get(HEADER_ID).add(factoryHeader.getHeaderView());
	}
	
	@Override
	public void setPresenter(Presenter presenter) {
		this.presenter = presenter;
	}

	@Override
	public void showCandidates(Presenter.Display display) {
		factoryHeader.getHeaderView().setModeCandidates();
		
		// ORDER IS IMPORTANT!!! 
		// Collapsible would not work if attached to non visible widget
		
		// Step 1
		RootPanel.get(MODULE_CANDIDATES_ID).setVisible(true);
		RootPanel.get(MODULE_COMPANIES_ID).setVisible(false);
		RootPanel.get(MODULE_ORDERS_ID).setVisible(false);
		RootPanel.get(MODULE_REPORTS_ID).setVisible(false);
		RootPanel.get(MODULE_SETTINGS_ID).setVisible(false);
		
	  // Step 2
		if (! ((Widget)display).isAttached()) {
			RootPanel.get(MODULE_CANDIDATES_ID).add((Widget) display);
		}
		
	}
	
	@Override
	public void showSettings(Presenter.Display display) {
		factoryHeader.getHeaderView().setModeSettings();
		
	  // ORDER IS IMPORTANT!!! 
		// Collapsible would not work if attached to non visible widget
		
		// Step 1
		RootPanel.get(MODULE_ORDERS_ID).setVisible(false);
		RootPanel.get(MODULE_COMPANIES_ID).setVisible(false);
		RootPanel.get(MODULE_CANDIDATES_ID).setVisible(false);
		RootPanel.get(MODULE_REPORTS_ID).setVisible(false);
		RootPanel.get(MODULE_SETTINGS_ID).setVisible(true);
		
		 // Step 2
		if (! ((Widget)display).isAttached()) {
			RootPanel.get(MODULE_SETTINGS_ID).add((Widget) display);
		}
		
	}
}
